package com.chb.docter.controller.apis;

import com.chb.docter.dto.CareOrderDto;
import com.chb.docter.dto.CheckOrderDetail;
import com.chb.docter.dto.OrderDetailsDto;
import com.chb.docter.dto.PatientAndCareHistoryDto;
import com.chb.docter.params.CareOrderParam;
import com.chb.docter.service.CareHistoryService;
import com.hos.entity.his.CareHistory;
import com.hos.entity.his.CareOrder;
import com.hos.entity.his.CareOrderItem;
import com.hos.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/12/14 10:22
 * @description:
 * @modified By:
 * @version:
 */
@RestController
@RequestMapping("docter/api/care")
@Api(tags = "患者信息相关接口")
public class ApiCareController {

    @Resource
    private CareHistoryService careHistoryService;


    @GetMapping("getPatientAllMessageByPatientId/{patientId}")
    @ApiOperation(value = "根据患者ID查询  患者信息 患者档案信息  历史病例")
    public Result<PatientAndCareHistoryDto> getPatientAllMessageByPatientId(@PathVariable String patientId) {
        return careHistoryService.getPatientAllMessageByPatientId(patientId);
    }

    @GetMapping("getCareHistoryByRegId/{regId}")
    @ApiOperation(value = "根据挂号ID查询病历信息")
    public Result<CareHistory> getCareHistoryByRegId(@PathVariable String regId) {
        CareHistory careHistory = careHistoryService.getCareHistoryByRegId(regId);
        return new Result<>(200, "查找成功", careHistory);
    }

    @PostMapping("saveCareHistory")
    @ApiOperation(value = "保存病历")
    public Result<CareHistory> saveCareHistory(@RequestBody CareHistory careHistory) {
        CareHistory result = careHistoryService.saveCareHistory(careHistory);
        return new Result<>(200, "保存成功", result);
    }


    @ApiOperation("保存处方及详情信息")
    @PostMapping("saveCareOrderItem")
    public Result<Void> saveCareOrderItem(@RequestBody CareOrderParam careOrderParam) {
        this.careHistoryService.saveCareOrderItem(careOrderParam);
        return new Result<>(200, "保存成功", null);
    }


    @ApiOperation("根据病例ID查询处方列表及详情")
    @GetMapping("queryCareOrdersByChId/{chId}")
    public Result<List<CareOrderDto>> queryCareOrdersByChId(@PathVariable String chId) {
        return new Result<>(200, "查询成功", this.careHistoryService.queryCareOrdersByChId(chId));
    }

    @PostMapping("visitComplete/{regId}")
    @ApiOperation("根据挂号单号完成就诊")
    public Result<Void> visitComplete(@PathVariable String regId) {
        this.careHistoryService.visitComplete(regId);
        return new Result<>(200, "保存成功", null);
    }

    @ApiOperation("根据处方详情ID删除处方详情【只能删除未支付的】")
    @DeleteMapping("deleteCareOrderItemById/{itemId}")
    public Result<Void> deleteCareOrderItemById(@PathVariable String itemId) {
        this.careHistoryService.deleteCareOrderItemById(itemId);
        return new Result<>(200, "删除成功", null);
    }

    @GetMapping("getRegistrationListByChId/{chId}")
    @ApiOperation("获取订单详情")
    public Result<OrderDetailsDto> getRegistrationListByChId(@PathVariable String chId) {
        return new Result<>(200, "查询成功", this.careHistoryService.getRegistrationListByChId(chId));
    }

    @GetMapping("getCareOrderListByCoType")
    @ApiOperation("获取检查处方的列表父项")
    public Result<List<CareOrder>> getCareOrderListByCoType() {
        return new Result<>(200, "查询成功", this.careHistoryService.getCareOrderListByCoType());
    }

    @GetMapping("getCheckOrderDetailsByItemId/{itemId}")
    @ApiOperation("通过开诊明细的id查询明细信息")
    public Result<CheckOrderDetail> getCheckOrderDetailsByItemId(@PathVariable String itemId) {
        return new Result<>(200, "查询成功", this.careHistoryService.getCheckOrderDetailsByItemId(itemId));
    }
}